package de.dhbw.karlsruhe.picsim.gui.util;

import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
import org.jetbrains.annotations.NotNull;
import org.jetbrains.annotations.Nullable;

/**
 * Created by IntelliJ IDEA.
 * User: user
 * Date: May 2, 2010
 * Time: 2:44:10 PM
 */
public final class GuiUtils {
    private static final Log log = LogFactory.getLog(GuiUtils.class);

    private GuiUtils() {
    }

    @Nullable
    public static Integer userInputToInt(@NotNull final String userInput) {
        try {
            return userInput.startsWith("0x")
                    ? Integer.parseInt(userInput.substring(2), 16)
                    : Integer.parseInt(userInput);
        } catch (NumberFormatException e) {
            log.info("Illegal User Input leads to", e);
            return null;
        }
    }
}
